﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Common;
using Model;
using Model.DB;
using Model.Sys;

namespace Controllers.Extend
{
    /// <summary>
    /// 用户基础控制器（“用户信息”的验证）
    /// </summary>
    public class UserBaseController : BaseController
    {
        protected UserInfo loginUser = null;
        protected string cookieName = "";
        protected string cookieValue = "";

        /// <summary>
        /// 获取已验证用户信息
        /// </summary>
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            var cookieValueTemp = CookieHelper.GetCookieValue(cookieName);
            if (!string.IsNullOrEmpty(cookieValueTemp))
            {
                cookieValue = cookieValueTemp;
                Cache cache = CurrentBllSession.CacheBll.GetCache(cookieValue);
                if (cache != null)
                {
                    this.loginUser = (UserInfo)cache.Value;
                }

            }
        }

        /// <summary>
        /// 执行前读取站点配置信息
        /// </summary>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
        }

        /// <summary>
        /// 返回结果前附加数据
        /// </summary>
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            if (this.loginUser != null)//给视图设置用户信息
            {
                ViewData["LoginUser"] = this.loginUser;
            }
        }
    }
}
